﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Tetris.Interfaces;

namespace Tetris.Graphics
{
    public class StaticBackgroundLayer :IDrawableObject
    {
        private readonly string _textureName;
        private Texture2D _texture;

        public StaticBackgroundLayer( string textureName )
        {
            _textureName = textureName;
        }

        public Vector2 Position
        {
            get { return new Vector2( 0, 0 ); }
            set
            {
                throw new InvalidOperationException( "Cant change position of a background layer!" );
            }
        }

        public int Width { get { return _texture.Width; } }
        public int Height { get { return _texture.Height; } }
        public bool Active { get { return true; } }

        public void Initialize( IGameManager gameManager )
        {
            _texture = gameManager.Game.Content.Load<Texture2D>( _textureName );
        }

        public void Update( IGameManager gameManager )
        {
            // Nothing to do since it is static
        }

        public void Draw( SpriteBatch spriteBatch, IGameManager gameManager, GameTime gameTime )
        {
            spriteBatch.Begin();
            spriteBatch.Draw( _texture, Vector2.Zero, Color.White );
            spriteBatch.End();
        }
    }
}
